﻿using System;

namespace Simple3DRedactor.Domain
{
    public interface IObjectView
    {
        event Action<IObjectView> Change;

        SceneObject InnerObject { get; }

        void OnRemove();
    }

    public abstract class ObjectView<T> : IObjectView where T : SceneObject
    {
        protected ObjectView(T obj)
        {
            if (obj == null) throw new ArgumentNullException("obj");

            InnerObject = obj;

            InnerObject.Change += OnObjectChange;
        }

        public T InnerObject { get; private set; }

        public virtual void OnRemove()
        {
        }

        public event Action<IObjectView> Change;
        protected void OnChange()
        {
            if (Change != null) Change(this);
        }

        SceneObject IObjectView.InnerObject
        {
            get { return InnerObject; }
        }
        
        protected virtual void OnObjectChange(SceneObject obj)
        {
            OnChange();
        }
    }
}
